package cn.innosmart.aq.bean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by David on 2015/12/1.
 */
public class WorkLogTemp {
    private String title;
    private String icon;
    private ArrayList<JSONObject> columns = new ArrayList<>();
    private ArrayList<Integer> display = new ArrayList<>();
    private String description;
    //日志栏目属性列表
    private JSONArray jsonColumns;
    private String id;

    public WorkLogTemp(JSONObject jsonObject) {
        try {
            this.id = jsonObject.getString("id");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        try {
            this.title = jsonObject.getString("title");

        } catch (JSONException e) {
            e.printStackTrace();
        }
        try {
            this.icon = jsonObject.getString("icon");

        } catch (Exception e) {

        }
        try {
            jsonColumns = jsonObject.getJSONArray("column");
            for (int i = 0; i < jsonColumns.length(); i++) {
                columns.add(jsonColumns.getJSONObject(i));
            }
        } catch (Exception e) {

        }
        try {
            this.description = jsonObject.getString("description");
        } catch (Exception e) {

        }
    }

    public WorkLogTemp() {

    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public JSONArray getJsonColumns() {
        return jsonColumns;
    }

    public void setJsonColumns(JSONArray jsonColumns) {
        this.jsonColumns = jsonColumns;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public ArrayList<Integer> getDisplay() {
        return display;
    }

    public void setDisplay(ArrayList<Integer> display) {
        this.display = display;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public ArrayList<JSONObject> getColumns() {
        return columns;
    }

    public void setColumns(ArrayList<JSONObject> columns) {
        this.columns = columns;
    }

    @Override
    public String toString() {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("title", title);
            jsonObject.put("icon", icon);
            jsonObject.put("column", columns);
            jsonObject.put("display", display);
            jsonObject.put("id", id);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return jsonObject.toString();
    }

    public JSONObject toJSonObject() {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("title", title);
            jsonObject.put("icon", icon);
            jsonObject.put("column", jsonColumns);
            jsonObject.put("display", display);
            jsonObject.put("id", id);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return jsonObject;
    }

}
